/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hessingerbg.codebehind;


/**
 *
 * @author MikeLaptop
 */
public class spellroutine implements subroutine {

    private boolean stopNeeded = false;
    private spellmanager spell;
    private spell next;
    private keyevent spellrobot;
    
    public spellroutine()
    {
        
        try {
            log.println("Initializing Ability Routines");
            spell = spellmanager.readFile();
            spellrobot = new keyevent();
            java.util.Collections.sort(spell);
        } catch (Exception ex) {
            //log.println(ex);
        }
    }

    public void doRoutine() {
        if (spell != null)
        {
            for(spell x : spell)
            {
                if(x.isValid() && x.isNotOnCD())
                {
                    next = x;
                    stopNeeded = x.isRequirescasting();
                    log.println(x.getName() + " is ready for use, queueing it now");
                    break;
                }
                else
                {
                    log.println(x.getName() + " is on cooldown or is not a valid ability");
                }
            }
        }
    }

    public boolean requiresStop() {
        return stopNeeded;
    }

    public double requiredStopSeconds()
    {
        return next.getCastingtime();
    }

    public void useSpell()
    {
        if(next != null)
        {
            log.println("Using " + next.getName());
            next.useSpell(spellrobot);
            next = null;
            stopNeeded = false;
        }
    }

    public void fullStop() {
        return;
    }



}
